package com.matriq.cloudmanager.fragment;

import com.matriq.cloudmanager.R;
import com.matriq.cloudmanager.ClassInfoActivity;
import com.matriq.cloudmanager.DownloadMngActivity;
import com.matriq.cloudmanager.LoginActivity;
import com.matriq.cloudmanager.MyApp;
import com.matriq.cloudmanager.PersonInfoActivity;
import com.matriq.cloudmanager.SetActivity;
import com.matriq.cloudmanager.SuggestActivity;
import com.matriq.cloudmanager.entity.User;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.lgpage.fragment.BaseFragment;

public class Personal2Fragment extends BaseFragment {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fm_personal2, container, false);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		setViews();
		setEvents();
		loadData();
	}

	TextView tv_num;
	LinearLayout ll[] = new LinearLayout[6];
	Button bt_logout;
	TextView tv_name;
	ImageView iv_head;
	LinearLayout ll_head;

	private void setViews() {
		tv_num = (TextView) getView().findViewById(R.id.tv_num);
		ll[0] = (LinearLayout) getView().findViewById(R.id.ll0);
		ll[1] = (LinearLayout) getView().findViewById(R.id.ll1);
		ll[2] = (LinearLayout) getView().findViewById(R.id.ll2);
		ll[3] = (LinearLayout) getView().findViewById(R.id.ll3);
		ll[4] = (LinearLayout) getView().findViewById(R.id.ll4);
		ll[5] = (LinearLayout) getView().findViewById(R.id.ll5);
		bt_logout = (Button) getView().findViewById(R.id.bt_logout);
		tv_name = (TextView) getView().findViewById(R.id.tv_name);
		iv_head = (ImageView) getView().findViewById(R.id.iv_head);
		ll_head = (LinearLayout) getView().findViewById(R.id.ll_head);
	}

	private void setEvents() {
		bt_logout.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				MyApp.getApp().outLogin();
				getActivity().finish();
				toActivity(LoginActivity.class);
			}
		});
		ll_head.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(PersonInfoActivity.class);
			}
		});
		ll[0].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
					
			}
		});
		ll[1].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(DownloadMngActivity.class);
			}
		});
		ll[5].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(SetActivity.class);
			}
		});
	}

	public void setData(User obj) {
		if (obj == null)
			return;
		tv_num.setText("学号:" + obj.getNO());
		tv_name.setText(obj.getName());
	}

	private void loadData() {
		setData(MyApp.getApp().getLoginObj());
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

}